package com.franz.noteapp.compose.showNotes.compose

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.material.MaterialTheme
import androidx.compose.material.RadioButton
import androidx.compose.material.RadioButtonDefaults
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.franz.noteapp.bean.NoteOrder
import com.franz.noteapp.bean.NoteType
import com.franz.noteapp.ui.theme.NoteTheme

/**
 * 排序选项*/
@Composable
private fun NoteRadioButton(text:String,selected:Boolean,modifier: Modifier = Modifier,onSelect:()->Unit){
    Row(
        modifier = modifier,
        verticalAlignment = Alignment.CenterVertically
    ) {
        RadioButton(
            selected = selected,
            colors = RadioButtonDefaults.colors(
                selectedColor = NoteTheme.colors.primary,
                unselectedColor = NoteTheme.colors.onBackground
            ),
            onClick = onSelect
        )

        Spacer(modifier = Modifier.width(0.dp))

        Text(text = text, style = MaterialTheme.typography.body1, color = NoteTheme.colors.primary)
    }
}

/**
 * 排序组件*/
@Composable
fun OrderSelect(noteType: NoteType = NoteType.Date(NoteOrder.Descending), modifier: Modifier = Modifier,onChangeListener:(NoteType)->Unit){
   Column(modifier = modifier) {
       Row(modifier = Modifier.fillMaxWidth()) {
           NoteRadioButton(text = "Title", selected = noteType is NoteType.Title) {
               onChangeListener(NoteType.Title(noteType.noteOrder))
           }

           Spacer(modifier = Modifier.width(8.dp))

           NoteRadioButton(text = "Date", selected = noteType is NoteType.Date) {
               onChangeListener(NoteType.Date(noteType.noteOrder))
           }

           NoteRadioButton(text = "Color", selected = noteType is NoteType.Color) {
               onChangeListener(NoteType.Color(noteType.noteOrder))
           }
       }

       Spacer(modifier = Modifier.height(10.dp))

       Row(modifier = Modifier.fillMaxWidth()) {
           NoteRadioButton(text = "Ascending", selected = noteType.noteOrder is NoteOrder.Ascending) {
               onChangeListener(noteType.copy(NoteOrder.Ascending))
           }

           Spacer(modifier = Modifier.width(8.dp))

           NoteRadioButton(text = "Descending", selected = noteType.noteOrder is NoteOrder.Descending) {
               onChangeListener(noteType.copy(NoteOrder.Descending))
           }
       }
   }
}